<?php

class Kzend_Controller_Helper_FormUtils extends Zend_Controller_Action_Helper_Abstract
{
    public function direct()
    {
        return $this->defaultMethod();
    }

    public function defaultMethod()
    {
        return null;
    }

    public function getSubmitValues($fieldsDef, $method = "post")
    {
        $request = $this->_actionController->getRequest();
        $svals = array();
        foreach ($fieldsDef as $def) {
            if ($method == "post") {
                $val = $request->getPost($def);
                if ($val !== null) {
                    $svals[$def] = $val;
                }
            } else if ($method == "get") {
                $val = $request->getQuery($def);
                if ($val !== null) {
                    $svals[$def] = $val;
                }
            }
        }

        return $svals;
    }

    public function pushedButtonName($buttonNameArray)
    {
        $take = null;
        $request = $this->_actionController->getRequest();
        foreach ($buttonNameArray as $bname) {
            $take = $request->getPost($bname);
            if ($take !== null) {
                return $bname;
            }
        }

        return false;
    }

    public function attachSubmitValues($stdObj, $svals)
    {
        foreach ($svals as $key => $val) {
            $stdObj->$key = $val;
        }
    }

}

